<?php
namespace app\admin\model;
use think\Db;
class Orderumoney{

    /**
     * 系统增减会员资金
     * @param unknown $user_id
     * @param unknown $action_user_id
     * @param unknown $money_type   资金类型
     * @param unknown $money
     * @param unknown $note
     */
    public function doit($user_id, $action_user_id, $money_type, $money, $note){
        $users = Db::name('user')->find($user_id);

        Db::startTrans();
        $mysql   = [];
        $order_no = com_order_no();
        #订单
        $d = [
            'user_id'       => $user_id,
            'order_no'      => $order_no,
            'action_user_id'=> $action_user_id,
            'money_type'    => $money_type,
            'money'         => $money,
            'note'          => $note,
            'create_time'   => time(),
        ];
        $mysql[] = $id = Db::name('order_umoney')->insertGetId($d);
        #扣款
        $b = new \app\index\model\Bill();
        if($money<0){
            $type = 208;
            $real_money = bcsub(0,$money,2);
        }else{
            $type = 108;
            $real_money = bcadd(0,$money,2);
        }
        $mysql[] = $b->create($order_no, $user_id,  $type, 'order_umoney', $id,  $money_type, $real_money,$note);

        if ($money_type=='zz_money') {
            //加增值积分 计算静态收益
            //减增值积分 ？？？？？
            //转账转入增值积分 是否计算静态收益
            com_error('请完善细节');
            com_check();
        }

        $check = true;
        foreach($mysql as $v){ if( !$v ){ $check = false; break;} }
        if( $check ){Db::commit();return true;}else{Db::rollback(); return com_error('变动资金失败');}
    }
}